<?php
/*
Template Name: Recent Posts
*/
?>
<?php get_header(); ?>
<div id="main_body">
    <div class="container">
        <?php get_sidebar(); ?>
        <div id="middle" />
        <div class="articles">
            <?php 
               // wp_reset_query(); 
                //query_posts("posts_per_page=2"); 
                $my_query = new WP_Query(array('paged' => get_query_var('paged')));
           ?>
            <?php if ($my_query->have_posts()) { ?>
   
               <h2>អត្ថបទ​ថ្មីៗ</h2>         
                <?php 
                    
                    $i = 0;
                    while ($my_query->have_posts()) : $my_query->the_post(); 
                        $i += 1;
                        if ($i == 1) {
                            main_article(); //display main article
                        } else {
                        ?>

                        <div <?php post_class() ?>>
                            <div class="post-thumbnail">
                                <?php the_post_thumbnail('thumbnail'); ?>
                            </div>
                            <div class="post-content">
                                <h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>

                                        <?php //include (TEMPLATEPATH . '/inc/meta.php' );   ?>

                                <div class="entry">
                                    <p>
                                    <?php echo get_the_excerpt(); ?>
                                        ...(<a class="readmore" href="<?php the_permalink(); ?>">អាន​លម្អិត</a>)
                                    </p>
                                </div>
                            </div>
                            <div class="clearfix"></div>

                        </div>

                    <?php 
                        }
                        endwhile; 
                        
                         if (function_exists('wp_pagenavi')) {
                             wp_pagenavi( array( 'query' => $my_query ) );

                         }
                         wp_reset_postdata();	// avoid errors further down the page
            } else {
     ?>

                <h2>ទំព័រ​កំពុង​រៀបចំ សូម​មេត្តា​ចូល​អាន​ពេល​ឆាប់ៗនេះ</h2>

    <?php } //end if ?>
        </div><!-- articles -->
    </div> <!-- middle -->
<?php wp_reset_query(); get_sidebar('right'); ?>
</div>
<div class="clearfix"></div>
</div><!-- #main -->
<?php get_footer(); ?>